package Costar;

import java.io.*;
import com.alibaba.fastjson.JSON;

public class CostarMain {
    public static void main(String[]args) throws Exception{
        //数据
        //String line = v1.toString();
        BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\Hadoop实训\\Film.json"));
        FileWriter fw=new FileWriter(new File("C:\\Users\\Administrator\\Desktop\\Hadoop实训\\Film.csv"));
        MovieInfo mi=null;
        String line=null;
        while((line=br.readLine())!=null){
            //Fastjson 把每行的json 字符串转换为对象。
            mi=JSON.parseObject(line,MovieInfo.class);
            if(mi.getActor().contains("郑佩佩")){
                //Film_page 作为电影ID
                String mid=mi.getFilm_page();
                //取出演员的列表
                String[] actors=mi.getActor().split(",");
                for(String act:actors){
                    if (!act.contains("郑佩佩")){
                        String ac;
                        ac = act;
                        //把电影数据写入csv文件。csv 表头为 ID,电影名称,评分,演员
                        fw.append(mid+","+mi.getTitle()+","+mi.getStar()+","+ac+"\n");
                    }
                }
            }
        }
        fw.close();
        br.close();
    }
}